package com.http.method;

import android.os.Handler;

import com.alibaba.fastjson.JSONObject;
import com.http.callback.RequestCallBack;

import java.io.IOException;
import java.net.HttpURLConnection;

/**
 * Created by wk on 15/1/19.
 */
public class StringRequest<T> extends Request<T> {
    private String type = CommonRequestType.HTML;
    private Class clazz;
    public StringRequest(String mUrl) {
        super(mUrl);
    }

    public StringRequest(String mUrl, RequestCallBack requestCallBack) {
        super(mUrl, requestCallBack);
    }

    public StringRequest(String mUrl, RequestCallBack requestCallBack, Handler handler1) {
        super(mUrl, requestCallBack, handler1);
    }

    @Override
    public void setRequestType(String type) {
        this.type = type;
    }

    @Override
    public String getRequestType() {
        return type;
    }

    @Override
    public void executeRequest(HttpURLConnection httpURLConnection) throws IOException {
        int code = httpURLConnection.getResponseCode();
        RequestResult requestResult = new RequestResult();
        String message = parseHttpUrlConnection(httpURLConnection);
        switch (code) {
            case 200:

                requestResult.requestCallBack = requestCallBack;
                requestResult.obj = message;
                handler.obtainMessage(SUCCESS,requestResult).sendToTarget();
                break;
            default:
                requestResult.requestCallBack = requestCallBack;
                requestResult.status_code = httpURLConnection.getResponseCode();
                requestResult.obj = message;
                handler.obtainMessage(ERROR,requestResult);
                break;
        }
    }

    @Override
    public int compareTo(Request<T> another) {
        return 0;
    }
}
